const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}
/**
 * 毫秒值转日期
 */
function timemillisToDateStrCompatible(timemillis) {
  var dateTime = new Date(timemillis);
  var year = dateTime.getFullYear();
  var month = dateTime.getMonth() + 1;
  var day = dateTime.getDate();
  var dateStr = year + '-' + zoon(month) + '-' + zoon(day);
  return dateStr;
}
function zoon(val) {
  let time = ''
  val < 10 ? time = '0' + val : time = val;
  return time
}
function isConstants(str) {
  let userPerminssions = wx.getStorageSync('PERMISSIONS')
  if (userPerminssions.indexOf(str) != -1) { //找不到则返回-1，找到则返回索引值
    return true
  }
  return false
}


module.exports = {
  formatTime: formatTime,
  timemillisToDateStrCompatible: timemillisToDateStrCompatible,
  isConstants: isConstants
}